
package simpleftp.client.control;

import java.io.File;
import java.util.concurrent.Callable;

import simpleftp.client.gui.FTPClientWindow;

/* Change : Download class  based on the Uploader class*/
public final class Download implements Callable<Boolean> {
        private SimpleFTP client;
        private String server;
        private String port;
        private FTPClientWindow wind;
        private String user;
        private String pass;
        public File f;
        public File dest;
        private String savePath;


        public Download(String savePath,File f, File dest, FTPClientWindow window, String server, String port, String user, String pass) {
                this.f = f;
                this.savePath=savePath;
                this.server = server;
                this.port = port;
                this.wind = window;
                this.user = user;
                this.pass = pass;
                this.dest = dest;
                client = new SimpleFTP();
        }

        @Override
        public Boolean call() throws Exception {
                System.out.println("Download starting for " + f.getName());
                Boolean result = false;
                client.connect(server, Integer.parseInt(port), user, pass);
                client.setNewPath(savePath);
                /* Change : We call the download function from the simpleFTP class*/
                result = client.download(f.getName(), dest);
                if (result) {
                        wind.console.append("Successfully downloaded f " + f.getName());
                        System.out.println("Successfully downloaded f " + f.getName());
                } 
                else {
                        wind.console.append("Failed downloading f " + f.getName());
                        System.out.println("Failed downloading f " + f.getName());
                }
                return result;
        }
}